filter_input
Get a specific external variable by name and can be processed by filter
filter_input()
function gets input from outside the script and filters it.
This function is used to verify variables from non-secure sources, such as user input.
This function can obtain input from various sources:
If successful, the filtered data is returned, if failed, false, if variable parameter is not set, NULL.
In this example, we use filter_input()
function to filter a POST variable. The accepted POST variable is a legal e-mail address.
<?php if ( ! filter_input ( INPUT_POST , 'email' , FILTER_VALIDATE_EMAIL ) ) { echo "E-Mail is not valid" ; } else { echo "E-Mail is valid" ; } ?>
The output is similar:
E-Mail is valid
filter_input ( input_type , variable , filter , options )
parameter | describe |
---|---|
input_type | Required. Specify the input type. See the possible types in the list above. |
variable | Specify the variables to be filtered. |
filter |
Optional. Specifies the ID of the filter to be used. The default is FILTER_SANITIZE_STRING. See the complete PHP Filter Function Reference Manual for possible filters. The filter ID can be an ID name (such as FILTER_VALIDATE_EMAIL), or an ID number (such as 274). |
options | Specifies an array containing flags/options. Check each filter for possible flags and options. |